<template>
  <div class="editForm-wrapper">
    <!-- 供应商编辑dialog-->
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      v-dialogDrag
      :visible.sync="editVisible"
    >
      <el-form
        label-width="95px"
        :rules="dataRule"
        ref="editForm"
        :model="editForm"
      >
        <el-form-item label="磅房名称:" prop="name">
          <el-input v-model="editForm.name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <div class="footer-input">
          <el-button size="small" type="primary" @click="doSubmit()" v-noMoreClick >确定</el-button>
          <el-button size="small" @click="editVisible = false">取消</el-button>
        </div>

      </span>
    </el-dialog>

  </div>
</template>
<script>

export default {

  data () {
    return {
      method: '',
      detailsVisible: false,
      areaLabel: {},
      title: '',
      editForm: {
        name: '',
        id: ''
      },
      editVisible: false,
      dataRule: {
        name: [
          { required: true, message: '请输入磅房名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
  	handleClose(done) {
		this.$Msg.confirm({
			title:'您确定要关闭吗？',
			content:this.GLOBAL.FORM_CLOSE_TIPS,
			confirmCall:()=>{
				done();
			}
		})
	},
    init (method, obj) {
      this.editForm.id = obj
      this.method = method
      if (method === 'add') {
        this.title = '新增磅房'
        this.editForm = {}
        this.editForm.state = 0
        this.editVisible = true
      } else if (method === 'edit') {
        this.title = '修改磅房'
        this.editVisible = true
        this.$nextTick(() => {
          if (method === 'edit') { // 修改或者查看
            this.$http({
              url: `/basis/poundroom/queryById?id=${this.editForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.editForm = this.recover(this.editForm, data.PoundRoom)
              this.editForm.oldLoginName = this.editForm.loginName
            })
          }
        })
      }
    },
    // 表单提交
    doSubmit () {
      this.$refs['editForm'].validate((valid) => {
        if (valid) {
          this.loading = true
          this.$http({
            url: `/basis/poundroom/save`,
            method: 'post',
            data: this.editForm
          }).then(({ data }) => {
            this.loading = false
            if (data && data.success) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500
              })
              this.editVisible = false
              this.addChildVisible = false
              this.$emit('refreshDataList')
            }
          })
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.view-container {
  margin-bottom: 20px;
  display: flex;
  .label-container {
    width: 150px;
    text-align: right;
    font-size: 16px;
    font-weight: 400;
    color: #666666;
  }

  .form-container {
    font-size: 14px;
    font-weight: 400;
    color: #333333;
    width: 200px;
  }
}
</style>
